<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<script>
			// 二分查找
			let arr = [4, 11, 15, 17, 19, 25, 30, 36];

			function sort(arr, n, key) {
				// debugger
				let low = 0,
					high = n - 1,
					mid;
				while (low <= high) {
					mid = Math.floor((low + high) / 2);
					if (arr[mid] == key) {
						return mid;
					} else if (arr[mid] > key) {
						high = mid - 1;
					} else if (arr[mid] < key) {
						low = mid + 1;
					}
				}
				return -1;
			}
			console.log(sort(arr, arr.length, 19));
		</script>
	</body>
</html>
